package com.android.zgx.msg;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;

public class Main extends Activity {
	/*
	 * Variable Definition
	 */
	private TextView mResultText;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		init();
		readMsgLog();
	}

	// Initialize Control and Variable
	private void init() {
		mResultText = (TextView) findViewById(R.id.resultText);

	}

	/*
	 * Android Msg Log
	 * 
	 * @Param ResultList for in/out
	 */
	private void readMsgLog() {
		// Access to the Content
		ContentResolver cr = getContentResolver();

		// Query for Msg Log
		final Cursor cursor = cr.query(Uri.parse("content://sms/sent"), new String[]{"address","body"},
				null, null, "address desc");

		// Work with Records
		String msg = "";
		for (int i = 0; i < cursor.getCount(); i++) {
			cursor.moveToPosition(i);
			
			int phoneColumn = cursor.getColumnIndex("address");  
            int smsColumn = cursor.getColumnIndex("body");  
            msg += cursor.getString(phoneColumn) + ":" + cursor.getString(smsColumn) + "\n";
		}
		mResultText.setText(msg);
	}
}